<%--
  Created by IntelliJ IDEA.
  User: 骆鹏
  Date: 2017/7/27
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>事件交办</title>
    <meta name="viewport" content="width=device-width, initial-scale=0.3, user-scalable=0, minimum-scale=0, maximum-scale=5.0,user-scalable=yes">
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/css/base.css">
    <style>
        .formUl li .dataul{
            width: 256px;
            height: 75px;
            padding: 5px 10px;
            border-radius: 4px;
            vertical-align: middle;
            margin-left: 10px;
            border:1px solid #ccc;
            overflow-y: auto;
        }
        .formUl li .dataul li{
            float: left;
            width: 60px;
            height: 60px;
            position: relative;
            margin-right: 10px;
            margin-bottom: 10px;
            margin-top: 5px;
        }
        .formUl li .dataul li b {
            position: absolute;
            top: -9px;
            right: -5px;
            line-height: 1;
            color: red;
            cursor: pointer;
        }
        .formUl li .dataul li img{
            width: 100%;
            height: 100%;
        }
        .newBtn{
            background: url(/img/newjian.png) no-repeat;
            padding-left:5px;
            border:none
        }
    </style>
    <script type="text/javascript" src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/jquery-validate.js"></script>
    <script src="/lib/validate-mothods.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/workflow/work/workform.js"></script>
</head>
<body>
<div class="headTop">
    <ul class="clearfix fl">
        <li class="headTopLi fl Querys active" data-type="0">未指派</li>
        <li class=" fl"><img style="margin-top: 3px;" src="/img/02.png" alt=""></li>
        <li class="headTopLi fl Querys" data-type="1">已指派</li>
    </ul>
    <a href="javascript:void (0)" style="text-align: center;line-height: 28px;height: 28px;width: 70px;" data-type="1" class="newBtn btnData" >新建</a>
</div>
<div style="margin: 0 auto;margin-top: 46px;height: 60px;width: 97%;" class="clearfix">

</div>


<div class="pagediv" style="margin: 0 auto;width: 97%;">
    <table>
        <thead>
        <tr>
            <th>序号</th>
            <th>事件描述</th>
            <th>提交人</th>
            <th>提交日期</th>
            <th>事件类型</th>
            <th>所属社区</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>

<div class="cont_form" style="display: none"></div>
<div id="dbgz_page" class="M-box3 fr" style="display: none">

</div>
<script>
    function validform() {//验证方法
        return  $("#datasave").validate({
            checkStart: true,
            focusInvalid: false,
            errorPlacement: function (error, element) { //错误信息位置设置方法
                layer.tips(error[0].innerText, $(element), {time: 2000, tipsMore: true});
            },
            rules: {//验证那个东西
                userName:{
                    required:true
                },
                dateTime:{
                    required:true
                },
                eventType:{
                    required:true
                },
                shenpiren:{
                    required:true
                },
                gridId:{
                    required:true
                },
                eventTypeParent:{
                    required:true
                }
            },
            messages: {//提示信息
                userName:{
                    required:'该项为必填项'
                },
                dateTime:{
                    required:'该项为必填项'
                },
                eventType:{
                    required:'该项为必填项'
                },
                shenpiren:{
                    required:'该项为必填项'
                },
                gridId:{
                    required:'该项为必填项'
                },
                eventTypeParent:{
                    required:'该项为必填项'
                }
            }
        })
    }
    function xiaoType(me) {
        $.get('/code/selectBT',{typr:2,parentNo:$(me).val()},function (json) {
            var str='<option value="">请选择</option>';
            for(var i=0;i<json.obj.length;i++){
                str+='<option value="'+json.obj[i].codeNo+'">'+json.obj[i].codeName+'</option>'
            }
            $('#eventTypes').html(str)
        },'json')
    }
    function buildFormData(){
        var arr = {};
        $(".cont_form").find('.form_item').each(function(i,v){
            var _this = $(this);
            arr[_this.attr('title')] = _this.attr('name');
        });
        return arr;
    }
    function filesTwo(mes) {
        var arr=mes.files;
        var bool=true;
        for(var i=0;i<arr.length;i++){
            if(arr[i].name.indexOf('.png')==-1&&arr[i].name.indexOf('.jpg')==-1&&arr[i].name.indexOf('.PNG')==-1&&arr[i].name.indexOf('.JPG')==-1){
                bool=false;
                break;
            }
        }
        if(!bool){
            $.layerMsg({content:'只能上传.png或.jpg格式！',icon:2});
            return
        }
        $('#datasave').prop('action','/flow/fileUpload?module=grid')

        $('#datasave').ajaxSubmit({
            type:'post',
            dataType:'json',
            success:function (json) {
                if(json.flag) {
                    var str='';
                    var arr=json.datas;
                    var attStrId='';
                    var attStrName='';
                    for(var i=0;i<arr.length;i++){

                        attStrId+=arr[i].attStrId+',';
                        attStrName+=arr[i].attStrName+'*';
                        str+='<li>' +
                            '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
                            '<b class="deleClear">x</b>' +
                            '<input type="hidden" name="attachmentNameIds" value="'+arr[i].attStrId+'">' +//id
                            '<input type="hidden" name="attachmentNametwo" value="'+arr[i].attStrName+'">' +//名字
                            '</li>'
                    }
                    $(me).parent().siblings('ul').html(str)
                    $(me).prev().val(attStrId)
                    $(me).next().val(attStrName)
                }else {
                    alert('异常')
                }

            }
        })

    }
    function inputHuixian(name,data) {
        if(data==undefined||data==''){
            return
        }
        $('[name="'+name+'"]').val(data)
    }


    function selectHuixian(names,data,fn) {
        if(data==undefined||data==''){
            return
        }
        var optionArr=$('[name="'+names+'"]').find('option');
        for(var i=0;i<optionArr.length;i++){
            if($(optionArr[i]).val()==data){
                $(optionArr[i]).prop('selected','selected')
            }else {
                $(optionArr[i]).removeProp('selected')
            }
        }
        if(fn!=undefined){
            fn();
        }
    }

    var me=null;

    var user_id='';

    var ajaxPage={
        data:{
            page:1,//当前处于第几页
            pageSize:10,//一页显示几条
            flowStatus:null,
            useFlag:true
        },
        page:function (num) {
            this.data.flowStatus=$('.headTop ul .active').attr('data-type');
            var me=this;
            $.post('/gridEventParting/selectbYfLOWstuts',me.data,function (json) {
                if(json.flag) {
                    var str = '';
                    var arr = json.datas
                    for (var i = 0; i < arr.length; i++) {
                        str += '<tr>' +
                            '<td>' + (i + 1) + '</td>' +
                            '<td>' + arr[i].eventInfo + '</td>' +
                            '<td>' + arr[i].userName + '</td>' +
                            '<td>' + arr[i].dateTime + '</td>' +
                            '<td>' + arr[i].codeName + '</td>' +
                            '<td>' + arr[i].gridName + '</td>' +
                            '<td>' +function () {
                                if(me.data.flowStatus==0){
                                    return  '<a href="javascript:void(0)" data-id="'+arr[i].eventId+'" class="btnData" data-type="2" style="margin-right: 10px;">编辑</a>' +
                                        '<a href="javascript:void(0)" data-id="'+arr[i].eventId+'"   class="deleteAthis">删除</a>'
                                } else {
                                    return '<a href="javascript:void(0)" data-id="'+arr[i].eventId+'"' +
                                        '  data-flowStep="'+arr[i].prcsId+'" data-prcsId="'+arr[i].flowPrcs+'" data-rumId="'+arr[i].rumId+'"  data-flowPrcs="'+arr[i].prcsId+'"  class="particulars">查看详情</a>'
                                }
                            }()
                        '</td></tr>'
                    }
                    $('.pagediv table tbody').html(str)
                    if(json.total>10){
                        $('#dbgz_page').show();
                        me.pageTwo(json.total, me.data.pageSize, me.data.page)
                    }else{
                        $('#dbgz_page').hide();
                    }
//                    me.pageTwo(json.total, me.data.pageSize, me.data.page)
                }else {
                    $('.pagediv table tbody').html('')
                }

            },'json')
        },
        pageTwo:function (totalData, pageSize,indexs) {
            var mes=this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage:'',
                endPage: '',
                current:indexs||1,
                callback: function (index) {

                    mes.data.page=index.getCurrent();
                    mes.page();
                }
            });
        }
    }

    ajaxPage.page(0)

    var formData=null;
    var fromDataRejects=null;
    var modifydata=null;
    var runids=null;
    var runnames=null;
    var beginTime=null;
    var beginUser=null;
    var prcsId=null;
    var flowPrcs=null;
    var formLength;
    var tableId=null;
    var jingbanUser=null;
    var fromDataRejectsTwo=null;
    var modifydataTwo=null;
    var urlStr=eval($.GetRequest().id);









    var userIdValue='';
    var eventTimeValue='';
    var eventInfoValue='';
    var eventInfos=''






    $(document).delegate('.deleteAthis','click',function () {
        var $id=$(this).attr('data-id');
        $.layerConfirm({title:'确定删除',content:'您确定要删除吗？',icon:0},function(){
            $.get('/gridEvent/deleteByPrimaryKey',{eventId:$id},function (json) {
                $.layerMsg({content:'删除成功！',icon:1},function(){
                    location.reload();
                });
            },'json')
        })
    })
    $(document).delegate('.particulars','click',function () {
        window.open('/workflow/work/workformPreView?flowId=201&flowStep='+$(this).attr('data-flowStep')+'&runId='+$(this).attr('data-rumId')+'&prcsId='+$(this).attr('data-prcsId')+'&tabId='+$(this).attr('data-id'))
    })




    var newshenpiren=null;
    var infoNames=null;
    var eventInfoName=null;


    $(document).delegate('.btnData','click',function () {//新建方法
        var $type=$(this).attr('data-type');
        var strTwo='';
        var arr=[];
        var $id;
        if($type==1){
            strTwo='新建';
            arr=['保存','交办'];
            $id='';
        }else if($type==2){
            strTwo='编辑';
            arr=['保存','交办'];
            $id=$(this).attr('data-id');
        }


        layer.open({
            title:strTwo,
            btn:arr,
            area:['100%','100%'],
//            offset: '50px',
            content:'<form id="datasave" action="" method="post" enctype="multipart/form-data">' +
            '<input multiple="multiple" type="file" name="file" onchange="filesTwo(this)" style="display: none">' +
            '<input type="hidden" name="flowStatus">' +
            '<input type="hidden" name="eventId" value="'+$id+'">' +
            '<ul class="formUl" style="width:500px;margin: 0 auto;">' +
            '<li class="clearfix"><label><b>*</b>提交人:</label>' +
            '<input type="text" id="userIds" name="userName" readonly="readonly" placeholder="请选择提交人">' +
            '<input type="hidden" name="userId">' +
            ' <div class="btntext" style="position: relative;height: 27px;width: 30px">' +
            '</div>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>提交时间:</label>' +
            '<input type="text" name="dateTime" readonly="readonly"  id="time"  placeholder="请输入提交时间">' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>所属社区:</label>' +
            '<select name="gridId"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>大事件类型:</label>' +
            '<select name="eventTypeParent" onchange="xiaoType(this)"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>小事件类型:</label>' +
            '<select name="eventType" id="eventTypes"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label>事件描述:</label>' +
            '<textarea name="eventInfo" id="theScopeOf" placeholder="请输入事件描述" ></textarea>' +
            '</li>' +
            '<li class="clearfix"><label>事件位置:</label>' +
            '<input type="text" name="location" placeholder="请输入事件位置">' +
            '</li>' +

            '<li class="clearfix"><label>图片描述:</label>' +
            '<ul class="btntext dataul">' +
            '</ul>' +
            '<div class="btntext" style="position: relative;height: 92px;width: 30px">' +
            '<input type="hidden" name="attachmentId">'+
            '<a href="javascript:void(0)" style="position: absolute;bottom: 0px;color: #2e8ded;" class="upDataLoad">上传</a>' +

            '<input type="hidden" name="attachmentName">'+
            '</div>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>指派人员:</label>' +
            '<input type="text" readonly="readonly" name="shenpiren">' +
            '</li>' +
            '</ul>' +
            '</form>',
            success:function () {
                $('[name="gridId"]').change(function () {
                    $.get('/gridInfo/selectByPrimaryKey?gridInfo='+$(this).val(),function (json) {
                        if(json.flag){
                            $('[name="shenpiren"]').val(json.data.directorName);
                            $('[name="shenpiren"]').attr('data-directorId',json.data.directorId);
                        }
                    },'json')
                })



                if($type==1) {

                    var time = {
                        elem: '#time',
                        format: 'YYYY-MM-DD hh:mm:ss',
                        min: laydate.now(),
                        max: '2999-12-31 23:59:59',
                        istime: true,//是否显示时分秒
                        istoday: true,//是否显示【今天】的按钮
                        isclear: true,//是否显示【清空】的按钮
                        festival: true,//是否显示节日
                        start: laydate.now(0, "YYYY-MM-DD hh:mm:ss"),  // 开始日期
                        fixed: false,   // 是否固定在可视区域
                        zIndex: 10000,  // css控制图层的遮罩效果（效果不明显）
                        ready: function (dates) {  // 选择好日期的回调
                            console.log(dates)
                        }
                    }
                    laydate(time);
                    $('#time').val(laydate.now(0, 'YYYY-MM-DD hh:mm:ss'));
                }



                $.when(
                    $.get('/gridInfo/gridSettingsTree?deptId=0&typeId=0',function (json) {
                        if(json.flag){
                            var str='<option value="">请选择</option>';
                            for(var i=0;i<json.obj.length;i++){
                                str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                            }
                            $('[name="gridId"]').html(str)


                        }
                    },'json')

                ).done(function () {
                    $.get('/code/selectBT',{typr:1},function (json) {
                        if(json.flag){
                            var str='<option value="">请选择</option>';
                            for(var i=0;i<json.obj.length;i++){
                                str+='<option value="'+json.obj[i].codeNo+'">'+json.obj[i].codeName+'</option>'
                            }
                            $('[name="eventTypeParent"]').html(str)


                        }
                    },'json')
                    validform();
                }).done(function () {
                    if($type==2){
                        $.get('/gridEvent/selectByPrimaryKey',{eventId:$id},function (json) {
                            if(json.flag){
                                inputHuixian('dateTime',json.data.dateTime)
                                selectHuixian('gridId',json.data.gridId,function () {
                                    $.get('/gridInfo/selectByPrimaryKey?gridInfo='+json.data.gridId,function (json) {
                                        if(json.flag){
                                            $('[name="shenpiren"]').val(json.data.directorName);
                                            $('[name="shenpiren"]').attr('data-directorId',json.data.directorId);
                                        }
                                    },'json')
                                })
                                selectHuixian('eventTypeParent',json.data.eventTypeParent,function () {
                                    $.get('/code/selectBT',{typr:2,parentNo:$('[name="eventTypeParent"]').val()},function (jsontwo) {
                                        var str='<option value="">请选择</option>';
                                        for(var i=0;i<jsontwo.obj.length;i++){
                                            str+='<option value="'+jsontwo.obj[i].codeNo+'">'+jsontwo.obj[i].codeName+'</option>'
                                        }
                                        $('#eventTypes').html(str)
                                        selectHuixian('eventType',json.data.eventType)
                                    },'json')



                                })
                                inputHuixian('location',json.data.location)
                                inputHuixian('eventInfo',json.data.eventInfo)
                                inputHuixian('attachmentId',json.data.attachmentId)
                                inputHuixian('attachmentName',json.data.attachmentName)
                                var attStrId='';
                                var attStrName='';
                                var arr=json.data.attachments2;
                                var str='';
                                for(var i=0;i<arr.length;i++){
                                    attStrId+=arr[i].attStrId+',';
                                    attStrName+=arr[i].attStrName+'*';
                                    str+='<li>' +
                                        '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
                                        '<b class="deleClear">x</b>' +
                                        '<input type="hidden" name="attachmentNameIds" value="'+arr[i].attStrId+'">' +//id
                                        '<input type="hidden" name="attachmentNametwo" value="'+arr[i].attStrName+'">' +//名字
                                        '</li>'
                                }
                                $('.dataul').html(str)


                            }
                        },'json')
                    }
                })






                $('[name="userId"]').val($.cookie('userId'))
                $('[name="userName"]').val(decodeURI($.cookie('userName')))




                $('.upDataLoad').click(function () {
                    me=this;
                    $('[name=file]').click()
                })





            },
            yes:function (index) {
                if(validform().form()) {

                    if($type==1){
                        $('#datasave').attr('action','/gridEventParting/addGridEvent')
                    }else if($type==2){
                        $('#datasave').attr('action','/gridEventParting/updateByPrimaryKeySelective')
                    }

                    $('[name="flowStatus"]').val(0)
                    $('#datasave').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (json) {
                            if(json.flag){
                                $.layerMsg({content:'操作成功！',icon:1},function(){
                                    $($('.headTop ul li')[0]).click()
                                });

                            }
                        }
                    })
                }else {
                    return false
                }
            },
            btn2:function (index) {
                if($('[name="shenpiren"]').val()==''){
                    alert('该社区没有城建专干，请在网格信息设置中进行增加！')
                    return;
                }




                if(validform().form()) {

                    if($type==1){
                        $('#datasave').attr('action','/gridEventParting/addGridEvent')
                    }else if($type==2){
                        $('#datasave').attr('action','/gridEventParting/updateByPrimaryKeySelective')
                    }
                    $('[name="flowStatus"]').val(1)
                    newshenpiren=$('[name="shenpiren"]').attr('data-directorId');
                    eventInfoName=$('[name="eventInfo"]').val();
                    userIdValue=$('[name="userId"]').val();
                    eventTimeValue=$('[name="dateTime"]').val();
                    eventInfoValue=$('[name="eventInfo"]').val();
                    eventInfos=$('[name="gridId"]').find("option:selected").text();
                    $('#datasave').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (json) {
                            if(json.flag){


                                tableId=json.data.eventId;

                                infoNames=json.data.infoName;


                                $.layerMsg({content:'操作成功！',icon:1},function(){


                                    $.when(
                                        $.get('/workflow/work/workfastAdd',{flowId:201,runId:'',prcsId:1,flowStep:1},function (json) {
                                            if(json.flag){
                                                runids=json.object.flowRun.runId;
                                                runnames=json.object.flowRun.runName;
                                                beginTime=json.object.flowRun.beginTime;
                                                beginUser=json.object.flowRun.beginUser;
                                                prcsId=json.object.flowRunPrcs.prcsId;
                                                flowPrcs=json.object.flowRunPrcs.flowPrcs;

                                                $.get('/gridEventParting/updateByPrimaryKeySelective',{
                                                    rumId:runids,eventId:tableId
                                                },function (json) {
                                                },'json')






                                                workForm.init({
                                                        formhtmlurl:'../../workflow/work/workfastAdd',//URL
                                                        resdata:{
                                                            flowId:201,
                                                            runId:runids,
                                                            prcsId:prcsId,
                                                            flowStep:1
                                                        },
                                                        flowStep:prcsId,//预览
                                                        target:'.cont_form'},
                                                    function (data,option) {
                                                        var fromDataReject = buildFormData();
                                                        var form_item=$('.cont_form .form_item');
                                                        var realData=[];
                                                        var radioArr = {};
                                                        var modifydatas =[];
                                                        formLength=option.formLength;
                                                        var flag = false;
                                                        for(var i=0;i<form_item.length;i++){
                                                            var baseData={};
                                                            var value="";
                                                            var obj = form_item.eq(i);
                                                            var datatype = obj.attr("data-type");
                                                            var key=obj.attr("name");
                                                            var ismust = obj.attr('ismust');
                                                            if(datatype=="select"){
                                                                value= obj.val()==0?'':form_item.eq(i).val();
                                                            }else if(datatype=="textarea" || datatype=="text"  ){
                                                                value=obj.val();
                                                            }else if(datatype=="checkbox"){
                                                                value=obj.attr('title');
                                                            }else if(datatype=="macros"){
                                                                if(obj.attr('type') == "text"){
                                                                    value= obj.val();
                                                                }else{
                                                                    if(obj.val() > -1){
                                                                        value = obj.val()+'_'+obj.find("option:selected").text();

                                                                    }

                                                                }
                                                            }else if(datatype == "radio"){
                                                                var name = obj.attr('name');
                                                                if(!radioArr[obj.attr('name')]){
                                                                    radioArr[obj.attr('name')] = true;
                                                                    if($("input[name='"+name+"']:checked").length>0){
                                                                        value= $("input[name='"+name+"']:checked").val();
                                                                    }else{
                                                                        value = "";
                                                                    }
                                                                }else{
                                                                    continue;
                                                                }
                                                            }else if(datatype == "macrossign"){
                                                                value= obj.html();

                                                            }else if(datatype == "imgupload"){
                                                                var url = obj.attr('src');

                                                                if(url!='/img/icon_uploadimg.png'){
                                                                    value= url;
                                                                }


                                                            }else{
                                                                value = obj.val();
                                                            }

                                                            if(ismust == 'true' && value == ""){
                                                                flag = true;
                                                                layer.msg('<fmt:message code="main.th.PleaseFill" />'+obj.attr('title'), {icon: 1});
                                                                break;
                                                            }
                                                            if( value!=null){
                                                                baseData["key"]=key;
                                                                baseData["value"]=value;

                                                                if(baseData["key"]=="DATA_3"){
                                                                    baseData["value"]=infoNames;
                                                                }else if(baseData["key"]=="DATA_54"){
                                                                    baseData["value"]=eventInfoName;
                                                                }else if(baseData["key"]=="DATA_21"){
                                                                    baseData["value"]=eventInfoValue;
                                                                }else if(baseData["key"]=="DATA_24"){
                                                                    baseData["value"]=eventInfos;
                                                                }
                                                                realData.push(baseData);
                                                            }
                                                            if(value != ''){

                                                                modifydatas.push(baseData);
                                                            }
                                                        }


                                                        formData=JSON.stringify(realData);
                                                        fromDataRejectsTwo=fromDataReject;
                                                        modifydataTwo=modifydatas;
                                                        datacol()
                                                    })
                                            }
                                        },'json')

                                    ).done(function () {







                                    })



                                });

                            }
                        }
                    })
                }else {
                    return false
                }
            }
        })
    })





    function datacol() {
        (function (fn) {
            $.get('/flowhook/selectByFlowId?folwId=201',function (json) {
                if(json.flag){
                    var arr=json.object.map.split(',');
                    for(var i=0;i<arr.length;i++){
                        if(i<arr.length-1) {
                            var objrct = {};
                            objrct.key = fromDataRejectsTwo[arr[i].split('=>')[1]]
//                                                    if(arr[i].split('=>')[1]=='DATA_11'){
//                                                         continue;
//                                                    }
                            objrct.value =(function () {
//                                                        if(arr[i].split('=>')[0]=='USER_ID'){
//                                                            return userIdValue
//                                                        }else
                                if(arr[i].split('=>')[0]=='EVENT_TIME'){
                                    return eventTimeValue
                                }else if(arr[i].split('=>')[0]=='EVENT_INFO'){
                                    return  eventInfoValue
                                }else {
                                    return ''
                                }
                            })()
                            modifydataTwo.push(objrct)
                        }
                    }
                    modifydata=JSON.stringify(modifydataTwo);
                    fromDataRejects=JSON.stringify(fromDataRejectsTwo)
                    fn()
                }
            },'json')
        })(function () {
            $.post('/workflow/work/nextwork',{
                flowId:201,runId:runids,runName:runnames,
                beginTime:beginTime,beginUser:beginUser,
                prcsId:prcsId,flowPrcs:flowPrcs,
                tableName:'grid_event',tabId:tableId,formdata:formData,
                fromDataReject:fromDataRejects,modifydata:modifydata,
                formLength:formLength
            },function (json) {
                if(json.flag){

                    (function (fn) {
                        $.get('/workflow/work/findbranch',{
                            flowId:201, flowPrcs:'1',
                            runId:runids
                        },function (json) {
                            if(json.flag){
                                jingbanUser=json.object.prcsUser.split(',');
                                var num=0;
                                for(var i=0;i<jingbanUser.length;i++){
                                    if(jingbanUser[i]==newshenpiren){
                                        fn(newshenpiren)
                                        break;
                                    }else {
                                        num++;
                                    }
                                }
                                if(num==jingbanUser.length){
                                    alert('网格信息设置与流程的审批人不一致,此记录已删除，请联系管理员设置经办人!');
                                    $.post('/gridEvent/deleteByPrimaryKey',{eventId:tableId},function (json) {
                                        if(json.flag){
                                            $($('.headTop ul li')[2]).click();
                                        }
                                    },'json')
                                    layer.closeAll();
                                }




                            }

                        },'json')
                    })(function (newshenpiren) {
                        var smsTypes='';
                        var smsTypesArr=$('.addactiveClass');
                        for(var i=0;i<smsTypesArr.length;i++){
                            if($(smsTypesArr[i]).hasClass('active')){
                                smsTypes+=$(smsTypesArr[i]).attr('data-id')+','
                            }else {
                                smsTypes+=','
                            }
                        }



                        $.post('/workflow/work/saveWork',{
                            flowId:201,runId:runids,runName:runnames,
                            beginTime:beginTime,beginUser:beginUser,
                            prcsId:prcsId,flowPrcs:'2',
                            prcsflag:1,jingbanUser:newshenpiren+",",
                            tableName:'grid_event',tabId:tableId,smsType:smsTypes
                        },function (json) {
                            if(json.flag){
                                $.layerMsg({content:'转交成功！',icon:1},function () {
//                                    $($('.headTop ul li')[2]).click();
                                    location.reload();
                                });
                            }
                        },'json')
                    })


                }
            },'json')
        })
    }

    $('.headTop ul li').click(function () {
        $(this).siblings('li').removeClass('active')
        $(this).addClass('active')
        ajaxPage.page($(this).attr('data-type'))

    })

    $(document).delegate('.deleClear','click',function () {
        var strArr=$(this).parent().parent().next().find('input')[0].value.split(',')
        var val=$(this).siblings('[name="attachmentNameIds"]').val();
        for(var i=0;i<strArr.length;i++){
            if(strArr[i]==val){
                strArr.splice(i, 1)
            }
        }
        $(this).parent().parent().next().find('input')[0].value=strArr.join(',')
        var strArrs=$(this).parent().parent().next().find('input')[1].value.split(',')
        var vals=$(this).siblings('[name="attachmentNametwo"]').val();
        for(var i=0;i<strArrs.length;i++){
            if(strArrs[i]==vals){
                strArrs.splice(i, 1)
            }
        }
        $(this).parent().parent().next().find('input')[1].value=strArrs.join(',')

        $(this).parent().remove();

    })


    $('.pagediv').delegate('.delete_b','click',function () {
        var ids=$(this).attr('data-id');
        var me=this;
        $.layerConfirm({title:'<fmt:message code="menuSSetting.th.suredeleteMenu"/>',content:'<fmt:message code="menuSSetting.th.isdeleteMenu"/>？',icon:0},function(){
            $.get('/document/deleteDoc',{id:ids},function (json) {
                if(json.flag){
                    $.layerMsg({content:'<fmt:message code="workflow.th.delsucess"/>！',icon:1},function(){
                        $(me).parent().parent().remove()
                    });
                }else {
                    $.layerMsg({content:'<fmt:message code="lang.th.deleSucess"/>！',icon:2});
                }
            },'json')
        })
    })
    if(urlStr!=undefined){
        parent.clearOpen()
        layer.open({
            title:'编辑',
            btn:['保存','上报'],
            area:['600px'],
            offset:'50px',
            content:'<form id="datasave" action="" method="post" enctype="multipart/form-data">' +
            '<input multiple="multiple" type="file" name="file" onchange="filesTwo(this)" style="display: none">' +
            '<input type="hidden" name="flowStatus">' +
            '<input type="hidden" name="eventId" value="">' +
            '<ul class="formUl">' +
            '<li class="clearfix"><label><b>*</b>提交人:</label>' +
            '<input type="text" id="userIds" name="userName"  readonly="readonly" placeholder="请选择提交人">' +
            '<input type="hidden" name="userId">' +
            ' <div class="btntext" style="position: relative;height: 27px;width: 30px">' +
            '</div>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>提交时间:</label>' +
            '<input type="text" name="dateTime" id="times" readonly="readonly"  placeholder="请输入提交时间">' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>所属社区:</label>' +
            '<select name="gridId"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>大事件类型:</label>' +
            '<select name="eventTypeParent" onchange="xiaoType(this)"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>小事件类型:</label>' +
            '<select name="eventType" id="eventTypes"><option value="">请选择</option></select>' +
            '</li>' +
            '<li class="clearfix"><label>事件描述:</label>' +
            '<textarea name="eventInfo" id="theScopeOf" placeholder="请输入事件描述" ></textarea>' +
            '</li>' +

            '<li class="clearfix"><label>事件位置:</label>' +
            '<input type="text" name="location" placeholder="请输入事件位置">' +
            '</li>' +
            '<li class="clearfix"><label>图片描述:</label>' +
            '<ul class="btntext dataul">' +
            '</ul>' +
            '<div class="btntext" style="position: relative;height: 92px;width: 30px">' +
            '<input type="hidden" name="attachmentId">'+
            '<a href="javascript:void(0)" style="position: absolute;bottom: 0px;color: #2e8ded;" class="upDataLoad">上传</a>' +

            '<input type="hidden" name="attachmentName">'+
            '</div>' +
            '</li>' +
            '<li class="clearfix"><label><b>*</b>审批人:</label>' +
            '<select name="shenpiren"><option value="">请选择</option></select>' +
            '</li>' +
            '</ul>' +
            '</form>',
            success:function () {
                validform();
                (function (fn) {
                    $.get('/gridInfo/selectByUid',function (json) {
                        if(json.flag){
                            var str='';
                            if(json.datas.length==0){
                                str='<option value="">请选择</option>';
                            }else {
                                str='';
                            }

                            for(var i=0;i<json.datas.length;i++){
                                str+='<option value="'+json.datas[i].userId+'">'+json.datas[i].viceDirectorIdName+'</option>'
                            }
                            $('[name="shenpiren"]').html(str)
                        }
                    },'json')
                })(function () {

                })





                $.when(
                    $.get('/gridInfo/gridSettingsTree?deptId=0&typeId=0',function (json) {
                        if(json.flag){
                            var str='<option value="">请选择</option>';
                            for(var i=0;i<json.obj.length;i++){
                                str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                            }
                            $('[name="gridId"]').html(str)


                        }
                    },'json')



                ).done(function () {
                    $.get('/code/selectBT',{typr:1},function (json) {
                        if(json.flag){
                            var str='<option value="">请选择</option>';
                            for(var i=0;i<json.obj.length;i++){
                                str+='<option value="'+json.obj[i].codeNo+'">'+json.obj[i].codeName+'</option>'
                            }
                            $('[name="eventTypeParent"]').html(str)


                        }
                    },'json')
                }).done(function () {
                    $.get('/gridCheck/selectByPrimaryKey',{checkId:urlStr},function (json) {
                        if(json.flag){
                            inputHuixian('dateTime',json.data.checkTime)
                            inputHuixian('eventInfo',json.data.checkInfo)
                            inputHuixian('location',json.data.location)
//                                var arr=json.data.attachments1;
//                                var str='';
//                                for(var i=0;i<arr.length;i++){
//                                    attStrId+=arr[i].attStrId+',';
//                                    attStrName+=arr[i].attStrName+'*';
//                                    str+='<li>' +
//                                        '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
//                                        '<b class="deleClear">x</b>' +
//                                        '<input type="hidden" name="attachmentNameIds" value="'+arr[i].attStrId+'">' +//id
//                                        '<input type="hidden" name="attachmentNametwo" value="'+arr[i].attStrName+'">' +//名字
//                                        '</li>'
//                                }
//                                $('.dataul').html(str)


                            urlStr=undefined;
                            $('[name="userId"]').val(json.data.userId)
                            $('[name="userName"]').val(json.data.userName)
                        }
                    },'json')

                })











                $('.upDataLoad').click(function () {
                    me=this;
                    $('[name=file]').click()
                })





            },
            yes:function (index) {
                if(validform().form()) {

//                    if($type==1){
                    $('#datasave').attr('action','/gridEvent/addGridEvent')
//                    }else if($type==2){
//                        $('#datasave').attr('action','/gridEvent/updateByPrimaryKeySelective')
//                    }

                    $('[name="flowStatus"]').val(0)
                    $('#datasave').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (json) {
                            if(json.flag){
                                $.layerMsg({content:'操作成功！',icon:1},function(){
                                    $($('.headTop ul li')[0]).click()
                                });

                            }
                        }
                    })
                }else {
                    return false
                }
            },
            btn2:function (index) {
                if($('[name="shenpiren"]').val()==''){
                    alert('该社区没有城建专干，请在网格信息设置中进行增加！')
                    return;
                }
                if(validform().form()) {
//                    if($type==1){
                    $('#datasave').attr('action','/gridEvent/addGridEvent')
//                    }else if($type==2){
//                        $('#datasave').attr('action','/gridEvent/updateByPrimaryKeySelective')
//                    }
                    $('[name="flowStatus"]').val(1)
                    newshenpiren=$('[name="shenpiren"]').val();
                    eventInfoName=$('[name="eventInfo"]').val();
                    userIdValue=$('[name="userId"]').val();
                    eventTimeValue=$('[name="dateTime"]').val();
                    eventInfoValue=$('[name="eventInfo"]').val();
                    $('#datasave').ajaxSubmit({
                        type: 'post',
                        dataType: 'json',
                        success: function (json) {
                            if(json.flag){


                                tableId=json.data.eventId;
                                infoNames=json.data.infoName;

                                $.layerMsg({content:'操作成功！',icon:1},function(){


                                    $.when(
                                        $.get('/workflow/work/workfastAdd',{flowId:201,runId:'',prcsId:1,flowStep:1},function (json) {
                                            if(json.flag){
                                                runids=json.object.flowRun.runId;
                                                runnames=json.object.flowRun.runName;
                                                beginTime=json.object.flowRun.beginTime;
                                                beginUser=json.object.flowRun.beginUser;
                                                prcsId=json.object.flowRunPrcs.prcsId;
                                                flowPrcs=json.object.flowRunPrcs.flowPrcs;

                                                $.get('/gridEvent/updateByPrimaryKeySelective',{
                                                    rumId:runids,eventId:tableId
                                                },function (json) {
                                                },'json')






                                                workForm.init({
                                                        formhtmlurl:'../../workflow/work/workfastAdd',//URL
                                                        resdata:{
                                                            flowId:201,
                                                            runId:runids,
                                                            prcsId:prcsId,
                                                            flowStep:1
                                                        },
                                                        flowStep:prcsId,//预览
                                                        target:'.cont_form'},
                                                    function (data,option) {
                                                        var fromDataReject = buildFormData();
                                                        var form_item=$('.cont_form .form_item');
                                                        var realData=[];
                                                        var radioArr = {};
                                                        var modifydatas =[];
                                                        formLength=option.formLength;
                                                        var flag = false;
                                                        for(var i=0;i<form_item.length;i++){
                                                            var baseData={};
                                                            var value="";
                                                            var obj = form_item.eq(i);
                                                            var datatype = obj.attr("data-type");
                                                            var key=obj.attr("name");
                                                            var ismust = obj.attr('ismust');
                                                            if(datatype=="select"){
                                                                value= obj.val()==0?'':form_item.eq(i).val();
                                                            }else if(datatype=="textarea" || datatype=="text"  ){
                                                                value=obj.val();
                                                            }else if(datatype=="checkbox"){
                                                                value=obj.attr('title');
                                                            }else if(datatype=="macros"){
                                                                if(obj.attr('type') == "text"){
                                                                    value= obj.val();
                                                                }else{
                                                                    if(obj.val() > -1){
                                                                        value = obj.val()+'_'+obj.find("option:selected").text();

                                                                    }

                                                                }
                                                            }else if(datatype == "radio"){
                                                                var name = obj.attr('name');
                                                                if(!radioArr[obj.attr('name')]){
                                                                    radioArr[obj.attr('name')] = true;
                                                                    if($("input[name='"+name+"']:checked").length>0){
                                                                        value= $("input[name='"+name+"']:checked").val();
                                                                    }else{
                                                                        value = "";
                                                                    }
                                                                }else{
                                                                    continue;
                                                                }
                                                            }else if(datatype == "macrossign"){
                                                                value= obj.html();

                                                            }else if(datatype == "imgupload"){
                                                                var url = obj.attr('src');

                                                                if(url!='/img/icon_uploadimg.png'){
                                                                    value= url;
                                                                }


                                                            }else{
                                                                value = obj.val();
                                                            }

                                                            if(ismust == 'true' && value == ""){
                                                                flag = true;
                                                                layer.msg('<fmt:message code="main.th.PleaseFill" />'+obj.attr('title'), {icon: 1});
                                                                break;
                                                            }
                                                            if( value!=null){
                                                                baseData["key"]=key;
                                                                baseData["value"]=value;

                                                                if(baseData["key"]=="DATA_3"){
                                                                    baseData["value"]=infoNames;
                                                                }else if(baseData["key"]=="DATA_54"){
                                                                    baseData["value"]=eventInfoName;
                                                                }
                                                                realData.push(baseData);
                                                            }
                                                            if(value != ''){

                                                                modifydatas.push(baseData);
                                                            }
                                                        }


                                                        formData=JSON.stringify(realData);
                                                        fromDataRejectsTwo=fromDataReject;
                                                        modifydataTwo=modifydatas;
                                                        datacol()


                                                    })
                                            }
                                        },'json')

                                    ).done(function () {







                                    })



                                });

                            }
                        }
                    })
                }else {
                    return false
                }
            }
        })

    }






</script>
</body>
</html>
